import React, { PureComponent, createRef } from 'react'


export class App extends PureComponent {
    constructor(){
        super()
        this.titleRef = createRef();
        this.titleEl =null;
    }
    getNativeDOM(){
        // 1.ref
        // console.log(this.refs.whyRef);
        // 2.createRef
        console.log(this.titleRef.current);
        // 3.函数
        // console.log(this.titleEl);
    }
  render() {
    return (
      <div>
        <p>App - ref</p>
        <h1 ref="whyRef">hello ref</h1>
        <h1 ref={this.titleRef}>你好 jack</h1>
        <h2 ref={el=>this.titleEl=el}>你好</h2>
        <button onClick={()=>this.getNativeDOM()}>获取DOM</button>
      </div>
    )
  }
}

export default App